/* GUI CONVERTED from rewois.p (converter v1.76) Wed Jun 12 14:07:16 2002 */
/* rewois.p - REPETITIVE LABOR TRANSACTION COMPONENT BACKFLUSH               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.8.4.9 $                                      */

/* REVISION: 1.0      LAST MODIFIED: 07/28/86   BY: PML                      */
/* REVISION: 1.0      LAST MODIFIED: 06/30/86   BY: EMB                      */
/* REVISION: 1.0      LAST MODIFIED: 10/30/86   BY: EMB *39*                 */
/* REVISION: 1.0      LAST MODIFIED: 03/03/87   BY: EMB *A25*                */
/* REVISION: 1.0      LAST MODIFIED: 02/13/87   BY: pml *A26*                */
/* REVISION: 2.0      LAST MODIFIED: 03/20/87   BY: emb *A45*                */
/* REVISION: 2.1      LAST MODIFIED: 06/15/87   BY: WUG *A66*                */
/* REVISION: 2.1      LAST MODIFIED: 11/20/87   BY: emb *A75*                */
/* REVISION: 2.1      LAST MODIFIED: 07/23/87   BY: WUG *A77*                */
/* REVISION: 2.1      LAST MODIFIED: 08/31/87   BY: WUG *A94*                */
/* REVISION: 2.1      LAST MODIFIED: 09/11/87   BY: WUG *A94*                */
/* REVISION: 2.1      LAST MODIFIED: 11/04/87   BY: WUG *A102*               */
/* REVISION: 2.1      LAST MODIFIED: 01/18/88   BY: WUG *A151*               */
/* REVISION: 4.0      LAST MODIFIED: 02/01/88   BY: emb *A170*               */
/* REVISION: 4.0      LAST MODIFIED: 02/29/88   BY: flm *A179*               */
/* REVISION: 4.0      LAST MODIFIED: 03/14/88   BY: RL  *A171*               */
/* REVISION: 4.0      LAST MODIFIED: 03/28/88   BY: WUG *A187*               */
/* REVISION: 4.0      LAST MODIFIED: 04/13/88   BY: emb *A198*               */
/* REVISION: 4.0      LAST MODIFIED: 05/24/88   BY: flm *A252*               */
/* REVISION: 4.0      LAST MODIFIED: 11/09/88   BY: emb *A527*               */
/* REVISION: 4.0      LAST MODIFIED: 02/09/89   BY: emb *A643*               */
/* REVISION: 5.0      LAST MODIFIED: 06/23/89   BY: MLB *B159*               */
/* REVISION: 5.0      LAST MODIFIED: 07/05/89   BY: BJJ *B106*               */
/* REVISION: 6.0      LAST MODIFIED: 03/14/90   BY: emb *D002*               */
/* REVISION: 6.0      LAST MODIFIED: 04/03/90   BY: WUG *D015*               */
/* REVISION: 6.0      LAST MODIFIED: 07/25/90   BY: emb *D033*               */
/* REVISION: 6.0      LAST MODIFIED: 07/06/90   BY: emb *D040*               */
/* REVISION: 6.0      LAST MODIFIED: 01/11/91   BY: emb *D297*               */
/* REVISION: 6.0      LAST MODIFIED: 03/14/91   BY: WUG *D472*               */
/* REVISION: 6.0      LAST MODIFIED: 05/09/91   BY: emb *D633*               */
/* REVISION: 6.0      LAST MODIFIED: 10/03/91   BY: alb *D887*               */
/* REVISION: 6.0      LAST MODIFIED: 12/03/91   BY: emb *D955*               */
/* REVISION: 6.0      LAST MODIFIED: 12/06/91   BY: emb *D959*               */
/* REVISION: 7.0      LAST MODIFIED: 10/08/91   BY: pma *F003*               */
/* REVISION: 7.0      LAST MODIFIED: 01/24/92   BY: pma *F003*               */
/* REVISION: 7.0      LAST MODIFIED: 02/12/92   BY: pma *F190*               */
/* REVISION: 7.0      LAST MODIFIED: 03/09/92   BY: smm *F230*               */
/* REVISION: 7.0      LAST MODIFIED: 10/12/92   BY: emb *G071*               */
/* Revision: 7.3      Last edit:     09/27/93   By: jcd *G247*               */
/* REVISION: 7.3      LAST MODIFIED: 11/03/92   BY: emb *G269*               */
/* REVISION: 7.3      LAST MODIFIED: 01/11/93   BY: emb *G689*               */
/* REVISION: 7.3      LAST MODIFIED: 04/21/93   BY: pma *GA01*               */
/* REVISION: 7.3      LAST MODIFIED: 12/07/93   BY: pxd *GG41*               */
/* REVISION: 7.3      LAST MODIFIED: 10/07/94   BY: pxd *FR90*               */
/*           7.3                     10/29/94   BY: bcm *GN73*               */
/* REVISION: 7.2      LAST MODIFIED: 08/17/95   BY: qzl *F0TC*               */
/* REVISION: 8.5      LAST MODIFIED: 11/19/95   BY: sxb *J053*               */
/* REVISION: 7.3      LAST MODIFIED: 01/16/96   BY: ame *G1K4*               */
/* REVISION: 7.3      LAST MODIFIED: 01/30/96   BY: jym *G1G0*               */
/* REVISION: 8.5      LAST MODIFIED: 12/26/96   BY: *H0Q8* Julie Milligan    */
/* REVISION: 8.6      LAST MODIFIED: 03/15/97   BY: *K04X* Steve Goeke       */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton      */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Murali Ayyagari   */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb               */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* REVISION: 9.1      LAST MODIFIED: 09/28/00   BY: *N0WD* Mudit Mehta       */
/* Revision: 1.8.4.5    BY: Niranjan R.    DATE: 07/13/01  ECO: *P00L*       */
/* Revision: 1.8.4.6    BY: Ellen Borden   DATE: 06/08/01  ECO: *P00G*       */
/* Revision: 1.8.4.7    BY: Jeff Wootton   DATE: 05/14/02  ECO: *P03G*       */
/* Revision: 1.8.4.8    BY: Dan Herman     DATE: 05/24/02  ECO: *P018*       */
/* $Revision: 1.8.4.9 $  BY: Steve Nugent   DATE: 06/06/02 ECO: *P07Y*  */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*V8:ConvertMode=Maintenance                                                 */

{mfdeclre.i}
{cxcustom.i "REWOIS.P"}

define shared variable wo_recno as recid.
define variable qty_left like tr_qty_chg.
define variable trqty like tr_qty_chg.
define variable wopart_wip_acct like pl_wip_acct.
define variable wopart_wip_sub like pl_wip_sub.
define variable wopart_wip_cc like pl_wip_cc.
define variable ref like glt_ref.
define variable open_ref like mrp_qty.

define shared variable ophist_recid as recid.
define variable eff_date as date.
define variable qty as decimal.
define variable serial like tr_serial.
define variable lotrf like tr_ref format "x(8)".
define variable loc like ld_loc.
define variable site like ld_site.
define variable lotqty like wod_qty_chg.
define variable totlotqty like wod_qty_chg.
define variable del-yn like mfc_logical.
define variable yn like mfc_logical.
define variable i as integer.
define variable wod_recid as recid.
define variable dr_acct like wopart_wip_acct.
define variable dr_sub like wopart_wip_sub.
define variable dr_cc like wopart_wip_cc.

define variable wo_entity like en_entity.
define variable from_entity like en_entity.
define variable gl_amt like glt_amt.
define variable srsite like sr_site.
define variable wopart like wo_part.

define new shared variable transtype as character format "x(7)".
define variable var_amt like glt_amt.
define variable glcost like sct_cst_tot.

define variable assay like tr_assay.
define variable grade like tr_grade.
define variable expire like tr_expire.
define variable prline like rps_line no-undo.

define variable cline like sr_lineid no-undo.
define variable glx_mthd like cs_method.
define variable glx_set like cs_set.
define variable cur_mthd like cs_method.
define variable cur_set like cs_set.
define variable gl_tmp_amt as decimal no-undo.
define shared variable h_wiplottrace_procs as handle no-undo.
define shared variable h_wiplottrace_funcs as handle no-undo.
{wlfnc.i} /* FUNCTION FORWARD DECLARATIONS */
{wlcon.i} /* CONSTANTS DEFINITIONS         */
define variable iss_trnbr like tr_trnbr no-undo.
define variable rct_trnbr like tr_trnbr no-undo.
define variable is_wo_issue as logical initial true no-undo.
define variable io_batch like cnsu_batch no-undo.

{pocnvars.i}

/* DETERMINE IF SUPPLIER CONSIGNMENT IS ACTIVE */
{gprun.i ""gpmfc01.p""
   "(input ENABLE_SUPPLIER_CONSIGNMENT,
     input 11,
     input ADG,
     input SUPPLIER_CONSIGN_CTRL_TABLE,
     output using_supplier_consignment)"}
/*GUI*/ if global-beam-me-up then undo, leave.


find op_hist where recid(op_hist) = ophist_recid no-lock no-error.
if not available op_hist then leave.
{&REWOIS-P-TAG1}

find first gl_ctrl no-lock.

eff_date  = op_date.
qty       = op_qty_comp.

find wo_mstr where recid(wo_mstr) = wo_recno.
assign wopart = wo_part
   wopart_wip_acct = wo_acct
   wopart_wip_sub = wo_sub
   wopart_wip_cc = wo_cc
   prline = wo_line
   site = wo_site.

find si_mstr where si_site = wo_site no-lock.
wo_entity = si_entity.

if wopart_wip_acct = "" then do:
   find pt_mstr where pt_part = wo_part no-lock no-error.
   if available pt_mstr then
      find pl_mstr where pl_prod_line = pt_prod_line no-lock no-error.
   if available(pl_mstr) then do:
         {gprun.i ""glactdft.p"" "(input ""WO_WIP_ACCT"",
                                   input pt_prod_line,
                                   input wo_site,
                                   input """",
                                   input """",
                                   input no,
                                   output wopart_wip_acct,
                                   output wopart_wip_sub,
                                   output wopart_wip_cc)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end. /* IF AVAILABLE PL_MSTR */
end.

for each pk_det no-lock where pk_user = mfguser:
/*GUI*/ if global-beam-me-up then undo, leave.


   if pk_qty <> 0 then do:

      /* GET PART MASTER INFORMATION */
      find pt_mstr where pt_part = pk_part no-lock no-error.
      release pl_mstr.
      if available pt_mstr
         then
      find pl_mstr no-lock where pl_prod_line = pt_prod_line
         no-error.
      if available pl_mstr then
      find pld_det no-lock
         where pld_prodline = pl_prod_line and pld_site = site no-error.

      find wo_mstr where recid(wo_mstr) = wo_recno.

      qty_left = pk_qty.
      cline = "-" + string(pk_part,"x(18)") + pk_reference.

      do for sr_wkfl while qty_left <> 0:

         assign loc = pk_loc
            srsite = ""
            serial = ""
            lotrf = ""
            trqty  = qty_left.

         srsite = wo_site.

         if available pt_mstr then do:
            find next sr_wkfl where sr_userid = mfguser
               and sr_lineid = cline no-error.
            if available sr_wkfl then do:
               srsite = sr_site.
               loc = sr_loc.
               serial = sr_lotser.
               lotrf = sr_ref.
               trqty = sr_qty.
               delete sr_wkfl.
            end.
         end.

         /*PARTS THAT ARE NOT ISSUED FROM THE WO SITE, MUST BE     */
         /*TRANSFERED TO THE WO SITE BEFORE THEY CAN BE ISSUED TO  */
         /*THE WORK ORDER                                          */
         assign
            glxcst = 0
            gl_amt = 0
            dr_acct = ""
            dr_sub = ""
            dr_cc = ""
            global_part = pk_part
            global_addr = ""
            transtype = "ISS-WO".
         if available pl_mstr then
         find pld_det no-lock where pld_prodline = pl_prod_line
            and pld_site = wo_site no-error.

         if available pt_mstr then do:
            /* UPDATE MATERIAL COSTS & VARIANCES CONSUMED */

            {gprun.i ""wowipmtl.p"" "(input wo_nbr,
                                               input wo_lot,
                                               input trqty,
                                               input srsite,
                                               input integer(pk_reference),
                                               output glx_set,
                                               output glx_mthd,
                                               output cur_set,
                                               output cur_mthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if srsite <> wo_site then do:
               /*POST ANY INTER-SITE COMPONENT TRANSFERS & COSTS    */
               {&REWOIS-P-TAG2}
               {gprun.i ""icxfer.p"" "(input wo_lot,
                                                input serial,
                                                input lotrf,
                                                input lotrf,
                                                input trqty,
                                                input wo_nbr,
                                                input wo_so_job,
                                                input """",
                                                input wo_project,
                                                input eff_date,
                                                input srsite,
                                                input loc,
                                                input wo_site,
                                                input pt_loc,
                                                input no,
                                                input """",
                                                input ?,
                                                input """",
                                                input 0,
                                                output glcost,
                                                output iss_trnbr,
                                                output rct_trnbr,
                                                input-output assay,
                                                input-output grade,
                                                input-output expire)"
                  }
/*GUI*/ if global-beam-me-up then undo, leave.

                  {&REWOIS-P-TAG3}
               glxcst = glcost.
            end.
            else do:
               {gpsct02.i &part=pt_part
                  &site=wo_site
                  &cost=sct_cst_tot
                  }
            end.
            assign
               dr_acct = wopart_wip_acct
               dr_sub = wopart_wip_sub
               dr_cc = wopart_wip_cc
               gl_amt = trqty * glxcst.
            /* ROUND TRANSFERRED COST TO BASE CURRENCY PRECISION */
            {gprun.i ""gpcurrnd.p"" "(input-output gl_amt,
                                               input gl_rnd_mthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            find first wod_det where wod_nbr = wo_nbr
               and wod_lot = wo_lot
               and wod_part = pt_part
               and wod_op = integer(pk_reference)
               no-lock no-error.
            if available wod_det
               and glx_mthd <> "AVG"
               then
               var_amt = (glxcst - wod_bom_amt) * trqty.
            else
               var_amt = 0.
         end.
         /* ROUND TRANSFER COST VARIANCE TO BASE CURRENCY PRECISION */
         {gprun.i ""gpcurrnd.p"" "(input-output var_amt,
                                            input gl_rnd_mthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /* ADDED SECOND EXCHANGE RATE, TYPE, SEQUENCE */
         /* ADDED CRSUB AND DRSUB BELOW */
         {&REWOIS-P-TAG4}
         {ictrans.i
            &addrid=wo_vend
            &bdnstd=0
            &cracct="if available pl_mstr then
                              if available pld_det then pld_inv_acct
                              else pl_inv_acct
                           else gl_inv_acct"
            &crsub="if available pl_mstr then
                              if available pld_det then pld_inv_sub
                              else pl_inv_sub
                           else gl_inv_sub"
            &crcc="if available pl_mstr then
                            if available pld_det then pld_inv_cc
                            else pl_inv_cc
                         else gl_inv_cc"
            &crproj=wo_project
            &curr=""""
            &dracct=dr_acct
            &drsub=dr_sub
            &drcc=dr_cc
            &drproj=wo_project
            &effdate=eff_date
            &exrate=0
            &exrate2=0
            &exratetype=""""
            &exruseq=0
            &glamt=gl_amt
            &lbrstd=0
            &line=0
            &location="(if srsite <> wo_site then pt_loc
                             else loc)"
            &lotnumber=op_wo_lot
            &lotserial=serial
            &lotref=lotrf
            &mtlstd=0
            &ordernbr=op_wo_nbr
            &ovhstd=0
            &part=pk_part
            &perfdate=?
            &price=glxcst
            &quantityreq=trqty
            &quantityshort=0
            &quantity="- trqty"
            &revision=""""
            &rmks=""""
            &shiptype=""""
            &site=wo_site
            &slspsn1=""""
            &slspsn2=""""
            &sojob=wo_so_job
            &substd=0
            &transtype=""ISS-WO""
            &msg=0
            &ref_site=tr_site
            }
            {&REWOIS-P-TAG5}

         /* UPDATE WORK ORDER WIP AMOUNT */

         qty_left = qty_left - trqty.

         /* CREDIT WIP FOR ANY MATERIAL RATE VARIANCE
         DUE TO CHANGE IN THE STD COST AT THE WORK ORDER SITE*/
         if var_amt <> 0 then do:
            create trgl_det.
            assign trgl_trnbr = tr_trnbr
               trgl_type = "RATE VAR"
               trgl_sequence = recid(trgl_det)
               trgl_dr_acct = wo_mvrr_acct
               trgl_dr_sub = wo_mvrr_sub
               trgl_dr_cc = wo_mvrr_cc
               trgl_dr_proj = ""
               trgl_cr_acct = dr_acct
               trgl_cr_sub  = dr_sub
               trgl_cr_cc = dr_cc
               trgl_cr_proj = wo_project
               trgl_gl_amt = var_amt.

            tr_gl_amt = tr_gl_amt - var_amt.

            /* POST ANY MATERIAL RATE VARIANCE TO GLT_DET RECORD */
            /* ADDED DR-SUB AND CR-SUB BELOW */
            {mficgl02.i &gl-amount=var_amt
               &tran-type=tr_type
               &order-no=tr_nbr
               &dr-acct=trgl_dr_acct
               &dr-sub=trgl_dr_sub
               &dr-cc=trgl_dr_cc
               &drproj=trgl_dr_proj
               &cr-acct=trgl_cr_acct
               &cr-sub=trgl_cr_sub
               &cr-cc=trgl_cr_cc
               &crproj=trgl_cr_proj
               &entity=wo_entity
               &find="false"
               &same-ref="icc_gl_sum"
               }
         end.

         /*ASSAY, GRADE, EXPIRE */
         if srsite <> wo_site then do:
            tr_assay = assay.
            tr_grade = grade.
            tr_expire = expire.
         end.

         /* CREATE CONSIGNMENT USAGE RECORDS IF CONSIGNMENT ENABLED*/
         /* AND CONSIGNMENT INVENTORY EXISTS.                      */
         if using_supplier_consignment then do:
            {gprunmo.i
               &program = ""pocnsix4.p""
               &module  = "ACN"
               &param   =  """(input wo_part,
                               input wo_site,
                               input right-trim(substring(serial,1,18)),
                               input lotrf,
                               output consign_flag)"""}

                /*IF CONSIGNED INVENTORY EXISTS, DETERMINE WHETHER TO */
                /*USE IT PRIOR TO UNCONSIGNED INVENTORY.              */
            if consign_flag then do:
               {gprunmo.i
                  &program = ""ictrancn.p""
                  &module  = "ACN"
                  &param   =  """(input wo_nbr,
                                  input wo_lot,
                                  input integer(pk_reference),
                                  input wo_so_job,
                                  input trqty,
                                  input serial,
                                  input wod_part,
                                  input wo_site,
                                  input loc,
                                  input lotrf,
                                  input eff_date,
                                  input tr_trnbr,
                                  input is_wo_issue,
                                  input-output io_batch)"""}


            end. /*If consign_flag*/
         end. /*IF USING_SUPPLIER_CONSIGNMENT*/

         if is_wiplottrace_enabled()
            and is_operation_queue_lot_controlled
            (wod_lot, wod_op, OUTPUT_QUEUE)
            and is_wocomp_wiplot_traced(wod_lot, pk_part)
         then do:
            /*REGISTER THE MATERIAL CONSUMED IN THE TRACING JOURNAL*/

            run add_trace_record in h_wiplottrace_procs
               (
               input OPERATION_HISTORY,
               input op_trnbr,
               input CONSUMED_MTL,
               input ITEM_MTL,
               input '',
               input 0,
               input pk_part,
               input serial,
               input
               if is_wocomp_reference_traced(wo_lot, pk_part)
               then lotrf
               else '',
               input trqty
               ).
         end.
      end.

      {&REWOIS-P-TAG6}
      find first wod_det where wod_lot = wo_lot
         and wod_part = pk_part
         and wod_op = integer(pk_reference) no-error.
      if not available wod_det then do:
         create wod_det.
         assign wod_lot = wo_lot
            wod_nbr  = wo_nbr
            wod_part = pk_part
            wod_op = integer(pk_reference)
            wod_site = wo_site
            wod_loc = loc
            wod_iss_date = eff_date.
      end.

      /* UPDATE WORK ORDER ALLOCATION ON CUMULATIVE ORDER */
      if wod_loc = ? then wod_loc = loc.
      if wod_iss_date = ? then wod_iss_date = eff_date.

      find in_mstr exclusive-lock
         where in_part = wod_part and in_site =
         wod_site no-error.
      if available in_mstr then do:
         if wod_qty_req >= 0 then
            in_qty_req = in_qty_req - max(wod_qty_req - wod_qty_iss,0).
         else
            in_qty_req = in_qty_req - min(wod_qty_req - wod_qty_iss,0).
      end.

      wod_qty_iss = wod_qty_iss + pk_qty.
      wod_qty_req = wod_qty_iss.
      wod_qty_chg = 0.
      wod_bo_chg = 0.

      if available in_mstr then do:
         if wod_qty_req >= 0 then
            in_qty_req = in_qty_req + max(wod_qty_req - wod_qty_iss,0).
         else
            in_qty_req = in_qty_req + min(wod_qty_req - wod_qty_iss,0).
      end.

   end.
end.
/*GUI*/ if global-beam-me-up then undo, leave.

